angular.module('moti.controllers.spotsdetail', ['directiveModule', 'moti.services.spotsService', 'moti.directive.modal'])
    .controller('spotsDetailCtrl', ['$scope', '$location', '$routeParams', 'SpotsInterface', '$modal', function($scope, $location, $routeParams, SpotsInterface, $modal){

        //获取单个景点
        SpotsInterface.getSpot($routeParams.regionId, $routeParams.spotId).then(function(data){
            $.each(data, function(i, n){
                (n === null || (n === "" && !$.isArray(n))) && (data[i] = "暂无");
            });
            if(data.audio == "暂无"){
                $(".audio-content").html("暂无");
            }else{
                $(".audio-content").html('<audio controls src="' + data.audio.url + '">您的浏览器不支持audio标签</audio>');
            }
            $scope.spots = data;
            $(".spot-content").html($scope.spots.content);
        });

        //删除景点
        var dalete_modal = $modal({
            id : 'delete-modal',
            text : '确认要删除此景点吗？该操作不可恢复！'
        });
        $scope.deleteSpot = function(){
            dalete_modal.show();
        };
        $("#delete-btn").off("click").on("click", function(){
            SpotsInterface.deleteSpot($routeParams.regionId, $routeParams.spotId).then(function(data){
                dalete_modal.hide();
                $modal({id : 'tip-modal', text : "删除景点成功"}).show().autoHide();
                $location.path('/regionsDetail/' + $routeParams.regionId);
            });
        });
    }]);